unit SenderBll;

interface

uses BaseBll, SenderModel, System.Generics.Collections;

type
  TSenderBll = class(TSingleBll<TSenderModel>)

  private

  protected
    procedure BeforeDelete(id: integer); override;
    procedure CheckInputData(data: TSenderModel); override;
  public
    constructor Create; override;
    destructor Destroy; override;

    // procedure getAll(list: TObjectList<TSenderModel>);
    function save(data: TSenderModel): integer; override;
    function update(data: TSenderModel): integer; override;

    procedure SetAsDefault(id:integer);
  end;

implementation

uses SenderDAO;
{ TSenderBll }

procedure TSenderBll.BeforeDelete(id: integer);
begin
  inherited;

end;

procedure TSenderBll.CheckInputData(data: TSenderModel);
begin
  inherited;

end;

constructor TSenderBll.Create;
begin
  inherited;
  dao := TSenderDAO.Create;

end;

destructor TSenderBll.Destroy;
begin
  dao.Free;
  inherited;
end;

function TSenderBll.save(data: TSenderModel): integer;
begin
  dao.StartTransaction;
  try
    if data.ISDEFAULT <> 0 then
    begin
      dao.excuteSQL('update sender set ISDEFAULT=0 ');
    end;
    result := inherited;
    dao.Commit;
  except
    dao.Rollback;
    raise;
  end;
end;

procedure TSenderBll.SetAsDefault(id: integer);
begin

end;

function TSenderBll.update(data: TSenderModel): integer;
begin

  dao.StartTransaction;
  try
    if data.ISDEFAULT <> 0 then
    begin
      dao.excuteSQL('update sender set ISDEFAULT=0 where id<>:id', [data.id]);
    end;
    result := inherited;
  except
    dao.Rollback;
    raise;
  end;
end;

end.
